﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSW.Framework.Common.Binding;
using System.ComponentModel;

namespace CSW.Security.UI.DevEx.Reports
{
    /// <summary>
    /// RoleAppFunctionReport
    /// </summary>
    public class RoleAppFunctionReport : BindableObject
    {
        /// <summary>The RoleID.</summary>
        public int RoleID { get; private set; }
        /// <summary>The Role Description.</summary>
        public string RoleDescription { get; private set; }
        /// <summary>The App Function Description.</summary>
        public string AppFunctionDescription { get; private set; }

        private RoleAppFunctionReport(Security_Role role, Security_RoleAppFunction appFunction)
        {
            RoleID = role.RoleID;
            RoleDescription = role.Description;
            AppFunctionDescription = (appFunction != null ? appFunction.Security_AppFunction.Description : "None");
        }

        /// <summary>
        /// Gets the report.
        /// </summary>
        public static BindingList<RoleAppFunctionReport> GetList()
        {
            IEnumerable<RoleAppFunctionReport> report =
                from r in SecurityTest.DataContextInstance.Security_Role
                join raf in SecurityTest.DataContextInstance.Security_RoleAppFunction
                on r equals raf.Security_Role into appfuncs
                from af in appfuncs.DefaultIfEmpty()
                select new RoleAppFunctionReport(r, af);

            return new BindingList<RoleAppFunctionReport>(report.ToList());
        }
    }
}
